<?php
	include ('../ftp.class.php');
	session_start();
	$ftp = unserialize($_SESSION['ftp_sess']);

	include ('../includes/functions.php');
	if($_GET['dir'] != "\'/\'")
	{
		$_SESSION['actdir'] = $_GET['dir'];
	}
	if(!empty($_SESSION['actdir']))
	{
		$ftp->changeDir( $_SESSION['actdir'] );
	}	
	if (isset($_GET['up']))
	{
		$ftp->levelUp();
		$_GET['dir'] = "";
	}
	
	$actdir = $ftp->getDir();
	
	if(empty($_GET['dir']))
	{
		$_SESSION['actdir'] = $actdir;
	}
	
	include ('../includes/actions.php');
?>
<script type="text/javascript">
	parent.document.title = 'Web-FTP :: <?php echo $actdir; ?>';
</script>

<div style="padding-bottom: 5px">
	<div style="padding-left: 5px; float: left">
		Aktuelles Verzeichnis: <br />
		<?php echo $actdir; ?><br />
	</div>
	<div id="loader" style="padding-right: 10px; float: right; display: none">
		<img src="images/ajax-loader.gif" />
	</div>
	<div style="clear:both"></div>
</div>
<ul>
<?php	
	$liste = $ftp->getFileList('', 1 );
	
	if ($actdir != "/")
	{
?>
	<li id="up" class="listdir" style="border-top: 1px solid #ccc"> 
	  <div class="li_hover">
		<div 
			class="listdiv" 
			title="Ordner nach oben" 
			onclick="ajaxfade('ajax/showdirectory.php?up&amp;dir=<?php echo $actdir; ?>', '#slider')" 
			style="width: 100%; float: none; height: 24px">
			..
		</div>
	  </div>
	</li>
<?php
	}
	
	if ($liste)
	{
		$i = 0;
		$toolID = 0;
		sksort($liste, "name", true);
		foreach ($liste as $dir => $ftplist)
		{
			if ($liste[$dir]['type'] == 'Dir')
			{
?>
	<li class="listdir">
	  	<div class="li_hover">
			<div 
				class="listdiv" 
				title="Ordner <?php echo $liste[$dir]['name']; ?> öffnen" 
				onclick="ajaxfade('ajax/showdirectory.php?dir=<?php echo $actdir; ?>/<?php echo $liste[$dir]['name']; ?>', '#slider')"><?php echo $liste[$dir]['name']; ?>
			</div>
			<div style="float: right; height: 24px; padding-right: 3px">
				<img 
					src="images/chmod.png" 
					title="Berechtigung ändern" 
					class="options" 
					alt="chmod" 
					onclick="chmod('<?php echo $liste[$dir]['chmod']; ?>', '<?php echo $liste[$dir]['name']; ?>', '<?php echo $actdir; ?>', '<?php echo $toolID; ?>')" />
				<img 
					src="images/delete.png" 
					title="Ordner löschen" 
					class="options" 
					alt="löschen" 
					onclick="deletest('<?php echo $liste[$dir]['name']; ?>', '<?php echo $actdir; ?>', 'dir', '<?php echo $toolID; ?>')" />
				<img 
					src="images/rename.png" 
					title="Umbenennen" 
					class="options" 
					alt="rename" 
					onclick="rename('<?php echo $liste[$dir]['name']; ?>', '<?php echo $actdir; ?>', 'dir', '<?php echo $toolID; ?>')" />
			</div>
			<div style="clear: both"></div>
	  	</div>
	  	<div style="overflow: hidden">
			<div id="tools_<?php echo $toolID; ?>" class="tools" style="overflow:hidden; position: relative">
				<div style="box-shadow: inset 0 0 8px #000; -webkit-box-shadow: inset 0 0 8px #000; box-shadow: inset 0 0 8px #000; position:relative; left: -10px; width: 620px">
					<div id="tool_<?php echo $toolID; ?>" style="width: 100%; position:relative;"></div>
				</div>		
			</div>
	  	</div>
	</li>

<?php
			$toolID++;
			}
		}
		foreach ($liste as $dir => $ftplist)
		{
			if ($liste[$dir]['type'] == 'File')
			{
				$endung = array_pop(explode(".", $liste[$dir]['name']));
				if (file_exists("../images/filetypes/{$endung}.png"))
				{
					$rowback = "../images/filetypes/{$endung}.png";
				}
				else
				{
					$rowback = "../images/filetypes/file.png";
				}				
				?>
				  <form name="downloadform_<?php echo $i; ?>" action="ajax/download.php" method="post">
					<input type="hidden" name="dir" value="<?php echo $actdir . "/" . $liste[$dir]["name"]; ?>" />
					<li class="listfile">
					  <div class="li_hover">
					    <div 
					    	class="listdiv" 
					    	title="Datei <?php echo $liste[$dir]["name"]; ?> herunterladen" 
					    	onclick="document.forms[<?php echo $i; ?>].submit();return false"
					    	style="background-image: url(<?php echo $rowback; ?>);
					    		   background-position: 3px 3px;" >
						  <?php echo $liste[$dir]['name']; ?>
					    </div>
					    <div style="float: right; height: 24px; padding-right: 3px">
					<?php
					if(is_editorfile($endung))
					{
					  ?>
						<img 
							src="images/edit.png"
							title="Datei bearbeiten"
							class="options"
							alt="edit"
							onclick="edit('<?php echo $actdir . "/" . $liste[$dir]['name']; ?>', '<?php echo $toolID; ?>', '<?php echo $actdir; ?>')" />
					  <?php
					}	
					  ?>
						<img 
							src="images/chmod.png" 
							title="Berechtigung ändern" 
							class="options" 
							alt="chmod" 
							onclick="chmod('<?php echo $liste[$dir]['chmod']; ?>', '<?php echo $liste[$dir]['name']; ?>', '<?php echo $actdir; ?>', '<?php echo $toolID; ?>')" />
						<img 
							src="images/delete.png" 
							title="Datei löschen" 
							class="options" 
							alt="löschen" 
							onclick="deletest('<?php echo $liste[$dir]['name']; ?>', '<?php echo $actdir; ?>', 'file', '<?php echo $toolID; ?>')" />
						<img 
							src="images/rename.png" 
							title="Umbenennen" 
							class="options" 
							alt="rename" 
							onclick="rename('<?php echo $liste[$dir]['name']; ?>', '<?php echo $actdir; ?>', 'file', '<?php echo $toolID; ?>')" />
					    </div>
						<div style="clear: both"></div>
	  				  </div>
	  				<div style="overflow: hidden">
					  <div id="tools_<?php echo $toolID; ?>" class="tools" style="overflow:hidden; position: relative">
						<div style="box-shadow: inset 0 0 8px #000; -webkit-box-shadow: inset 0 0 8px #000; box-shadow: inset 0 0 8px #000; position:relative; left: -10px; width: 620px">
						  <div id="tool_<?php echo $toolID; ?>" style="width: 100%; position:relative;"></div>
						</div>		
					  </div>
	  				</div>
				  </li>
				  </form>
				<?php
				$i++;
				$toolID++;
			}
		}
	} 
	?>
	</ul>
	<div style="margin: 5px 8px 0 8px">
		<img 
			src="images/new_directory.png" 
			title="Neuer Ordner" 
			class="options" 
			style="margin:0 5px 0 0; cursor:pointer" 
			onClick="newdirectory('<?php echo $actdir; ?>')" />
		<img 
			src="images/new_file.png" 
			title="Neue Datei" 
			class="options" 
			style="margin:0 5px 0 0; cursor:pointer" 
			onClick="newfile('<?php echo $actdir; ?>')" />
		<img 
			src="images/upload.png" 
			title="Datei Hochladen" 
			class="options" 
			style="margin:0 5px 0 0; cursor:pointer" 
			onClick="upload('<?php echo $actdir; ?>')" />
	</div>